<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>ZDH HTTP任务首页</title>
    <meta name="keywords" content="ZDH HTTP任务首页">
    <meta name="description" content="ZDH HTTP任务首页">

    <link rel="shortcut icon" href="img/favicon.ico">

    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="css/plugins/datetimepicker/datetimepicker.css" rel="stylesheet">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link rel="stylesheet" data-name="vs/editor/editor.main" href="js/plugins/vs/editor/editor.main.css">
    <link rel="stylesheet" href="js/plugins/vs/editor/zdh.css">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>HTTP任务配置</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="buttons.html#">
                            <i class="fa fa-eye"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="javascript:void(0);" onclick="getResourceDesc()">功能说明</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="ibox-content">

                    <form id="dispatch_task_add_form" name="dispatch_task_add_form" method="post" class="form-horizontal"
                          action="">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">HTTP说明</label>
                            <div class="col-sm-10">
                                <input id="etl_context" name="etl_context" type="text"
                                       placeholder="HTTP说明" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">请求类型</label>
                            <div class="col-sm-10">
                                <select id="url_type" name="url_type" data-placeholder="请求类型"
                                        class="chosen-select form-control m-b" tabindex="2">
                                    <option value="0" mytype="" selected="selected">POST</option>
                                    <option value="1" mytype="">GET</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">请求地址</label>
                            <div class="col-sm-10">
                                <input id="url" name="url" type="text" class="form-control" placeholder="http://127.0.0.1:8081/xxxx">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">代理地址</label>
                            <div class="col-sm-10">
                                <input id="proxy_url" name="proxy_url" type="text" class="form-control" placeholder="例子: http://127.0.0.1:8081, 无代理可不填写">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">Header</label>
                            <div class="col-sm-10">
                                <div id="header" name="header"
                                     class="monaco_div_100"></div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">Cookie</label>
                            <div class="col-sm-10">
                                <div id="cookie" name="cookie"
                                     class="monaco_div_100"></div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">请求参数</label>
                            <div class="col-sm-10">
                                <div id="params" name="params"
                                     class="monaco_div_100"></div>
                                <span class="help-block m-b-none"><a id="system_params" href="javascript:void(0);"
                                                                     onclick="system_params()">系统内置参数</a></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">结果解析</label>
                            <div class="col-sm-10">
                                <div id="res_expr" name="res_expr"
                                     class="monaco_div_100"></div>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">是否禁用</label>
                            <div class="col-sm-10">
                                <div class="checkbox i-checks">
                                    <label class="no-padding">
                                        <input id="is_disenable" name='is_disenable'  type="checkbox"><i></i> 禁用</label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">依赖级别</label>
                            <div class="col-sm-10">
                                <select id="depend_level" name="depend_level" data-placeholder="依赖级别"
                                        class="chosen-select form-control m-b" tabindex="2">
                                    <option value="0" mytype="">成功触发</option>
                                    <option value="1" mytype="">杀死触发</option>
                                    <option value="2" mytype="">失败触发</option>
                                    <option value="3" mytype="">上游完成触发</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">调度器</label>
                            <div class="col-sm-10">
                                <input id="schedule_id" name="schedule_id" type="text" value=""
                                       placeholder="调度器标识" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">超时时间</label>
                            <div class="col-sm-10">
                                <input id="time_out" name="time_out" type="text" value="86400"
                                       placeholder="任务超时时间,以秒为单位,example: 100" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="text-center">
                                <button id="save_etl_info" name="save_etl_info" class="btn btn-primary" οnsubmit='return false'
                                        type="button">保存
                                </button>
                            </div>
                        </div>

                    </form>


                </div>
            </div>



        </div>
    </div>
</div>


<script src="js/zdh_common.js"></script>
<script>
    var require = {
        paths: {
            'vs': 'js/plugins/vs'
        }
    };

</script>
<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>

<!-- Bootstrap table -->
<script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

<!-- 自定义js -->
<script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="js/hplus.js?v=4.1.0"></script>
<script src="js/content.js?v=1.0.0"></script>

<!-- Chosen -->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<!-- layer javascript -->
<script src="js/plugins/layer/layer.min.js"></script>

<!-- Toastr script -->
<script src="js/plugins/toastr/toastr.min.js"></script>

<!-- iCheck -->
<script src="js/plugins/iCheck/icheck.min.js"></script>


<script src="js/plugins/layer/laydate/laydate.js"></script>


<script src="js/plugins/vs/loader.js"></script>
<script src="js/plugins/vs/editor/editor.main.nls.js"></script>
<script src="js/plugins/vs/editor/editor.main.js"></script>

<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });

    });

    (function(document, window, $) {


        (function () {


            window.editor_params = monaco.editor.create(document.getElementById('params'), {
                value: '',
                language: 'json',
                theme:'vs-dark'
            });

            window.editor_header = monaco.editor.create(document.getElementById('header'), {
                value: 'Key:Value格式,每行一个,多个请换行',
                language: 'shell',
                theme:'vs-dark'
            });

            window.editor_cookie = monaco.editor.create(document.getElementById('cookie'), {
                value: 'Key:Value格式,每行一个,多个请换行',
                language: 'shell',
                theme:'vs-dark'
            });

            window.editor_res_expr = monaco.editor.create(document.getElementById('res_expr'), {
                value: 'res != null',
                language: 'java',
                theme:'vs-dark'
            });

            var url = decodeURI(location.search); //这一条语句获取了包括问号开始到参数的最后，不包括前面的路径
            var params = url.substr(1);//去掉问号
            var pa = params.split("&");
            var s = new Object();
            for(var i = 0; i < pa.length; i ++){
                s[pa[i].split("=")[0]] = unescape(pa[i].split("=")[1]);
            }
            $('#url_type').chosen();
            $('#depend_level').chosen();
            if(s["etl_context"] != '-1'){
                console.info("更新触发");
                $('#url').val($("#http_url_text",window.parent.document).val());
                $('#proxy_url').val($("#http_proxy_url_text",window.parent.document).val());

                $('#url_type').val(s.url_type);
                $("#url_type").trigger("chosen:updated");
                $('#etl_context').val(s.etl_context);
                $("#schedule_id").val(s["schedule_id"]);
                $("#depend_level").val(s["depend_level"]);
                $("#depend_level").trigger("chosen:updated");
                window.editor_params.setValue($("#http_params",window.parent.document).val());
                window.editor_header.setValue($("#http_header",window.parent.document).val());
                window.editor_cookie.setValue($("#http_cookie",window.parent.document).val());
                window.editor_res_expr.setValue($("#http_res_expr",window.parent.document).val());

                if (!s["time_out"] && typeof(s["time_out"])!="undefined"){
                    $("#time_out").val(s["time_out"]);
                }
                var is_disenable=s['is_disenable'];
                if(is_disenable=="true"){
                    $('#is_disenable').iCheck('check');
                }
            }
        })();



    })(document, window, jQuery);

    $('#save_etl_info').click(function () {

        //自定义实现
        var url=$('#url').val();
        var proxy_url=$('#proxy_url').val();
        var url_type=$('#url_type').find("option:selected").val();
        var etl_context=$('#etl_context').val();
        var params=window.editor_params.getValue();
        var header=window.editor_header.getValue();
        var cookie=window.editor_cookie.getValue();
        var res_expr=window.editor_res_expr.getValue();
        var depend_level=$('#depend_level').find("option:selected").val();
        var schedule_id=$('#schedule_id').val();
        var time_out=$('#time_out').val();

        var is_disenable = "false";
        if($('#is_disenable').is(':checked')){
            is_disenable="true"
        }
        data={
            "etl_context":etl_context,
            "url":url,
            "proxy_url":proxy_url,
            "url_type":url_type,
            "is_disenable":is_disenable,
            "params":params,
            "depend_level":depend_level,
            "schedule_id": schedule_id,
            "time_out": time_out,
            "header": header,
            "cookie": cookie,
            "res_expr": res_expr
        };
        console.info("http_detail:"+JSON.stringify(data));
        $("#etl_task_text",window.parent.document).val(JSON.stringify(data));
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    })
</script>


</body>

</html>
